package models

import (
	"fmt"
	"log"
	"rongyy/src/app"
)

type PaymentTrackModel struct {
	BaseModel  `xorm:"extends"`
	JsonInput  PaymentReq `json:"json_input" xorm:"json"`
	StatusCode int        `json:"status_code"`
	ErrorMsg   string     `json:"error_msg"`
	JsonOutput string     `json:"json_output" xorm:"json"`
}

type ReqPaymentTrack struct {
	Limit     int    `json:"limit"`
	Offset    int    `json:"offset"`
	PatientId string `json:"patient_id"`
	Hospital  string `json:"hospital"`
	OrderSn   string `json:"order_sn"`
	HisCode   string `json:"his_code"`
}

func (rm *PaymentTrackModel) TableName() string {
	return "payment_track_log"
}

func (rm *PaymentTrackModel) String() string {
	return fmt.Sprintf("userid")
}

func (rm *PaymentTrackModel) Create() error {
	_, err := app.DB().Insert(rm)
	if err != nil {
		log.Println(err)
		return err
	}
	return nil
}

//
//func (rm *PaymentTrackModel) QueryTrackOrder(req *ReqTrack) ([]PaymentTrackModel, int64, error) {
//	regs := make([]PaymentTrackModel, 0)
//	//local, _ := time.LoadLocation("Asia/Shanghai")
//	//t := time.Now().In(local).Format("2006-01-02 15:04:05")
//	fmt.Println(req.HisCode)
//	fmt.Println("req.HisCode")
//	s := app.DB().Table("orders_track")
//	if req.PatientId != "" {
//		pid := fmt.Sprintf("%%%s%%", req.PatientId)
//		s.Where("patient_id like ?", pid)
//	}
//
//	if req.OrderSn != "" {
//		orderSn := fmt.Sprintf("%%%s%%", req.OrderSn)
//		s.Where("order_sn like ?", orderSn)
//	}
//
//	if req.HisCode != "" {
//		hisCode := fmt.Sprintf("%%%s%%", req.HisCode)
//		s.Where("his_code like ?", hisCode)
//	}
//	total, err := s.Limit(req.Limit, req.Offset).Desc("created_at").FindAndCount(&regs)
//	if err != nil {
//		return nil, 0, err
//	}
//	return regs, total, err
//}
